"use strict";

var _etagHash = require("etag-hash");

export default function stream2etag(stream) {
  var partSizeInMb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
  return new Promise(function (resolve, reject) {
    var hash = (0, _etagHash.createHash)(partSizeInMb);
    stream.on('error', function (error) {
      reject(error);
    }).on('data', function (chunk) {
      hash.update(chunk);
    }).on('end', function () {
      resolve(hash.digest());
    });
  });
};